import 'dart:convert';

import 'package:flutter_base/common/utils/utils.dart';
import 'package:flutter_base/common/values/values.dart';
import 'package:flutter_base/common/widgets/widgets.dart';
import 'package:flutter/material.dart';

class SearchTimeLineWidget extends StatefulWidget {
  final String? title;
  final String? subTitle;
  final String date;
  final String? status;
  final String? userName;
  final String? signature;
  final String? remark;
  final bool top;
  final bool bottom;
  const SearchTimeLineWidget({Key? key,  this.title, this.subTitle, required this.date, this.status, this.userName,  required this.top, required this.bottom, this.signature, this.remark}) : super(key: key);

  @override
  _SearchTimeLineWidgetState createState() => _SearchTimeLineWidgetState();
}

class _SearchTimeLineWidgetState extends State<SearchTimeLineWidget> {
  @override
  Widget build(BuildContext context) {
    return Container(
      color: Colors.white,
      child: Stack(
        children: <Widget>[
          widget.bottom
              ? Positioned(
            top: widget.top ? 66.0 : 0.0,
            left: zhiSetWidth(28),
            child: Container(
              width: 2.5,
              color: Colors.grey[300],
              height: 30,
            ),
          )
              : new Positioned(
            top: widget.top ? 66.0 : 0.0,
            bottom: widget.bottom
                ? isEmpty(widget.signature ?? '')
                ? zhiSetHeight(100)
                : zhiSetHeight(140)
                : 0.0,
            left: zhiSetWidth(28),
            child: Container(
              width: 2.5,
              color: Colors.grey[300],
            ),
          ),
          Padding(
            padding: const EdgeInsets.symmetric(vertical: 16.0),
            child: new Row(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: <Widget>[
                new Padding(
                  padding:
                  new EdgeInsets.symmetric(horizontal: 10, vertical: 6),
                  child: new Stack(
                    children: [
                      Container(
                        margin: EdgeInsets.only(right: 10),
                        width: zhiSetWidth(40),
                        height: zhiSetWidth(40),

                        //边框设置
                        decoration: new BoxDecoration(
                          //背景
                          color: AppColors.primaryElement,
                          //设置四周圆角 角度
                          borderRadius: BorderRadius.all(Radius.circular(6.0)),
                          //设置四周边框
                        ),
                        child: Center(
                          child: Text(
                            nickName(
                                widget.userName ??
                                ''),
                            style: TextStyle(
                                color: Colors.white,
                                fontWeight: FontWeight.w500),
                          ),
                        ),
                      ),
                      Positioned(
                        child: ClipOval(
                          child: StatusIcon(widget.status),
                        ),
                        right: 3,
                        bottom: -2,
                      ),
                    ],
                  ),
                ),
                new Expanded(
                  child: Padding(
                    padding: const EdgeInsets.only(right: 10, top: 3),
                    child: Column(
                      mainAxisSize: MainAxisSize.min,
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Container(
                          padding: EdgeInsets.symmetric(horizontal: 8),
                          child: Row(
                            children: [
                              Text(
                                 widget.title=='开始'?'发起申请': widget.title?? '',
                                style: TextStyle(
                                    fontWeight: FontWeight.w500, fontSize: 16),
                              ),
                              Spacer(),
                              Text(
                                formatDateStr(widget.date,
                                    format: 'yyyy-MM-dd HH:mm'),
                                // formatDateStr(widget.item?.createTime??'',format: 'yyyy-MM-dd HH:mm'),
                                style: TextStyle(color: Colors.grey),
                              ),
                            ],
                          ),
                        ),
                        // Container(
                        //   padding: EdgeInsets.symmetric(horizontal: 8),
                        //   child: Text(
                        //     formatDateStr(widget.date,
                        //         format: 'yyyy-MM-dd HH:mm'),
                        //     // formatDateStr(widget.item?.createTime??'',format: 'yyyy-MM-dd HH:mm'),
                        //     style: TextStyle(color: Colors.grey),
                        //   ),
                        // ),
                        Padding(
                          padding: const EdgeInsets.all(8.0),
                          child: Text(
                              '${widget.subTitle ?? ''}${StatusString(widget.status ?? '')}'),
                        ),
                        // Wrap(
                        //   children: users.map<Widget>((item) {
                        //     return Padding(
                        //       padding: const EdgeInsets.all(8.0),
                        //       child: Column(
                        //         crossAxisAlignment: CrossAxisAlignment.center,
                        //         children: [
                        //           Container(
                        //             // margin: EdgeInsets.only(right: 10),
                        //             width: zhiSetWidth(30),
                        //             height: zhiSetWidth(30),
                        //
                        //             //边框设置
                        //             decoration: new BoxDecoration(
                        //               //背景
                        //               color: AppColors.primaryElement,
                        //               //设置四周圆角 角度
                        //               borderRadius: BorderRadius.all(
                        //                   Radius.circular(6.0)),
                        //               //设置四周边框
                        //             ),
                        //             child: Center(
                        //               child: Text(
                        //                 nickName(item),
                        //                 style: TextStyle(
                        //                     fontSize: 12,
                        //                     color: Colors.white,
                        //                     fontWeight: FontWeight.w500),
                        //               ),
                        //             ),
                        //           ),
                        //           Text(item,
                        //               style: TextStyle(
                        //                 fontSize: 12,
                        //                 color: Colors.grey,
                        //               )),
                        //         ],
                        //       ),
                        //     );
                        //   }).toList(),
                        // ),
                        isEmpty(widget.remark ?? '')
                            ? Container()
                            : FractionallySizedBox(
                          child: Container(
                              margin: EdgeInsets.only(left: 8),
                              padding: EdgeInsets.all(8),
                              child: Text(widget.remark!),
                              decoration: new BoxDecoration(
                                //背景
                                color: Colors.grey[200],
                                //设置四周圆角 角度
                                borderRadius: BorderRadius.all(
                                    Radius.circular(4.0)),
                              )),
                          widthFactor: 1,
                        ),
                        isEmpty(widget.signature ?? '')||widget.title=='开始'
                            ? Container()
                            : Padding(
                          padding: const EdgeInsets.only(left: 8,top: 10),
                          child: Row(
                            children: [
                              Text('签名：'),

                              // loadAssetImage(
                              //   widget.item?.signature??'',
                              //   width: zhiSetWidth(100),
                              // )
                              Image.memory(
                                base64.decode(widget.signature!.replaceAll(
                                    'data:image/png;base64,', '')),
                                fit: BoxFit.contain,
                                width: zhiSetWidth(100),
                                // height: zhiSetWidth(60),
                              ),
                            ],
                          ),
                        )
                        // Text('我'),
                      ],
                    ),
                  ),
                ),
              ],
            ),
          )
        ],
      ),
    );
  }
  Widget StatusIcon(String? status) {
    switch (status) {

    ///同意
      case '1':
        return loadAssetImage('icon_agree',
            width: zhiSetWidth(16), height: zhiSetWidth(16));

    ///退回
      case '0':
        return loadAssetImage('icon_return',
            width: zhiSetWidth(16), height: zhiSetWidth(16));
    ///拒绝
      case '2':
        return loadAssetImage('icon_refuse',
            width: zhiSetWidth(16), height: zhiSetWidth(16));
    ///待审批
      case '4':
        return loadAssetImage('icon_doing',
            width: zhiSetWidth(16), height: zhiSetWidth(16));
      default:
        return Container();
    }
  }

  String StatusString(String status) {
    switch (status) {
      // case '1':
      //   return '（已同意）';
      // case '0':
      //   return '（退回）';
      // case '2':
      //   return '';
      default:
        return '';
    }
  }
}
